/**
* Created by wust on 2019/5/16.
*/
<template xmlns:v-data-dictionary-directive="http://www.w3.org/1999/xhtml">
  <el-form ref="formModel" :model="formModel" :rules="rules" label-width="250px" style="width:70%;" @submit.native.prevent>
    <el-form-item label="App ID" prop="appId">
      <el-input v-model="formModel.appId"  maxlength="50" show-word-limit :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="申请者">
      <el-input v-model="formModel.applicant"></el-input>
    </el-form-item>
    <el-form-item label="过期时间" prop="appExpireTime" style="text-align: left">
      <el-date-picker
        v-model="formModel.appExpireTime"
        align="right"
        type="date"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="签名保留时长（分钟）" prop="signDuration" style="text-align: left">
      <el-input-number v-model="formModel.signDuration" :min="1" :max="10"></el-input-number>
    </el-form-item>
    <el-form-item label="备注">
      <el-input
        type="textarea"
        :rows="6"
        placeholder="请输入内容"
        maxlength="255"
        show-word-limit
        v-model="formModel.description">
      </el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <select class="form-control" v-data-dictionary-directive:A1012="formModel.status" v-model="formModel.status">
      </select>
    </el-form-item>
    <el-form-item style="text-align: left;">
      <el-button type="primary" @click="onSubmit('formModel')" :loading="submitting">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import Vue from 'vue'

export default {
  name: 'app-token-update',
  props: ['selectedModel'],
  data () {
    return {
      submitting: false,
      addModel: {
        id: '',
        appId: '',
        appExpireTime: '',
        signDuration: 0,
        applicant: '',
        description: '',
        status: ''
      },
      rules: {
        appId: [{required: true, message: '请输入应用程序ID', trigger: 'blur'}],
        appExpireTime: [{required: true, message: '请选择应用程序过期时间', trigger: 'blur'}],
        signDuration: [{required: true, message: '请输入接口签名保留时长', trigger: 'blur'}]
      }
    }
  },
  created: function () {
    this.formModel = this.selectedModel
  },
  methods: {
    onSubmit: function (formData) {
      this.$refs[formData].validate((valid) => {
        if (!valid) {
        } else {
          this.submitting = true
          Vue.$ajax({
            method: 'put',
            url: Vue.$adminServerURL + '/web/v1/AppTokenController',
            data: this.formModel
          }).then(res => {
            this.submitting = false
            if (res.data.flag !== 'SUCCESS') {
              if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                this.$message({
                  message: res.data.message,
                  type: 'warning'
                })
              }
            } else {
              this.$message({
                message: res.data.message,
                type: 'success'
              })
            }
          })
        }
      })
    }
  }
}
</script>
